package com.controller;



import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.ajax.AjaxRes;
import com.common.mybatis.Page;
import com.entity.XinWenLanMu;
import com.service.XinWenLanMuService;

@Controller
@RequestMapping("/xinwenlanmu/manager")
public class XinWenLanMuController {

	@Autowired
	private XinWenLanMuService xwlmService;

	@RequestMapping("/findByPage")
	@ResponseBody
	public AjaxRes findByPage(XinWenLanMu lm,Page<XinWenLanMu> page){
		AjaxRes res = new AjaxRes();
		page = xwlmService.findByPage(lm, page);
		res.setSucceed(page,"成功");
		return res;
	}
	@RequestMapping("/addxwlm")
	@ResponseBody
	public AjaxRes addxwlm(XinWenLanMu lm){
		AjaxRes res = new AjaxRes();
		xwlmService.insert(lm);
		res.setResMsg("成功");
		return res;
	}
	@RequestMapping("/delxwlm")
	@ResponseBody
	public AjaxRes delxwlm(XinWenLanMu lm){
		AjaxRes res = new AjaxRes();
		xwlmService.delete(lm);
		res.setSucceedMsg("删除成功");
		return res;
	}
	
	@RequestMapping("/delAllxwlm")
	@ResponseBody
	public AjaxRes delAllxwlm(String cks){
		AjaxRes res = new AjaxRes(); 
		String[] ck = cks.split(",");
		List<XinWenLanMu> list = new ArrayList<XinWenLanMu>();
		for(String s:ck){
			XinWenLanMu lm = new XinWenLanMu();
			lm.setId(s);
			list.add(lm);
		}
		xwlmService.deleteBatch(list);
		res.setSucceedMsg("删除成功");
		return res;
	}

	
	@RequestMapping("/updatexwlm")
	@ResponseBody
	public AjaxRes updatexwlm(XinWenLanMu lm){
		AjaxRes res = new AjaxRes();
		xwlmService.update(lm);
		res.setSucceedMsg("修改成功");
		return res;
	}

	@RequestMapping("/find")
	@ResponseBody
	public AjaxRes find(XinWenLanMu lm){
		AjaxRes res = new AjaxRes();
		List<XinWenLanMu> xwlmList = xwlmService.find(lm);
		res.setSucceed(xwlmList,"获取数据成功");
		return res;
	}
	
}
